//@author A0096466N
//
// **********
//
// takes the most recent future 
// from history and redoes it
//
// **********

#include "Redo.h"

Redo::Redo(void) {

}

Redo::~Redo(void) {

}

string Redo::execute(History & history,vector<Task> & forUIDisplay, vector<Task> & store) {

	ofstream writeFile;
	writeFile.open(FILENAME_LOGGER.c_str(), ofstream::out | ofstream::app);
	writeFile << "Attempting to redo" << endl;
	writeFile.close();


	if(history.getFutureSize() == NIL) {
		throw exception("No future to redo from");
	}

	Event redo = history.getFuture();
	Task task = redo.getTask();
	string command = redo.getCommand();

	assert(command != EMPTY);

	if(command == ADD) {
		Add add;
		add.execute(task,store);
		Searcher search;
		forUIDisplay = search.execute(task.getTaskName(),store);
		history.transferToPast();
		return (REDONE + command);

	} else if(command == DELETE_) {
		Delete del;
		del.execute(task,forUIDisplay,store);
		history.transferToPast();
		return (REDONE + command);
	
	} else if(command == MARK) {
		Mark mark;
		mark.execute(task,forUIDisplay,store);
		history.transferToPast();
		return (REDONE + command);
	
	} else if(command == MODIFY) {
		Modify modify;
		modify.execute(task,forUIDisplay,store);
		history.transferToPast();	
		return (REDONE + command);
	
	} else if(command == RESET) {
		Reset reset;
		reset.execute(forUIDisplay,store);
		history.transferToPast();
		return (REDONE + command);
	
	} else {
		throw exception("redo error");
	}
}